PROCEDURE get1vdflag1:
    DEFINE INPUT  PARAMETER vpart LIKE pt_part.
    DEFINE INPUT  PARAMETER vvend LIKE vd_addr.
    DEFINE INPUT  PARAMETER datet AS DATE.
    DEFINE OUTPUT PARAMETER v1vd AS LOGICAL.

    DEFINE VARIABLE vprodline LIKE pt_prod_line NO-UNDO.
    ASSIGN v1vd = YES.
    FOR FIRST pt_mstr NO-LOCK WHERE pt_part = vpart:
        ASSIGN vprodline = pt_prod_line.
    END.
    IF vprodline = "R190" THEN DO:
        ASSIGN v1vd = NO.
    END.
    ELSE do:
        FOR FIRST CODE_mstr NO-LOCK WHERE  CODE_fldname= 'PT2D9EID'
              AND CODE_VALUE = STRING(YEAR(DATET),"9999") +
                              STRING(MONTH(DATET),'99'):
                  IF CODE_CMMT = 'PT9E' THEN DO:
                    IF NOT CAN-FIND(FIRST pt9e_det NO-LOCK
                                    WHERE pt9e_id =INT(CODE_DESC)
                                      AND pt9e_part=vpart) THEN DO:
                        ASSIGN v1vd = NO.
                    END.
                    FOR EACH pt9e_det NO-LOCK WHERE pt9e_id =INT(CODE_DESC)
                                                AND pt9e_part=vpart:
                        IF pt9e_vend <> vvend OR
                           pt9e_sub_part <> vpart THEN DO:
                            ASSIGN  v1vd = NO.
                        END.
                    END.
                 END.
                 ELSE DO:
                     IF NOT CAN-FIND(FIRST pt2D_det NO-LOCK
                                     WHERE pt2D_id =INT(CODE_DESC)
                                       AND pt2D_part=vpart) THEN DO:
                        ASSIGN v1vd = no.
                    END.
                    FOR EACH pt2D_det NO-LOCK WHERE pt2D_id =INT(CODE_DESC)
                                                AND pt2D_part=vpart:
                        IF pt2D_vend <> vvend OR
                           pt2d_SUB_part <> vpart THEN DO:
                            ASSIGN v1vd = NO.
                        END.
                    END.
                 END.
        END.
    END.
END PROCEDURE.

PROCEDURE get1vdflag3:
    DEFINE INPUT PARAMETER vPart LIKE pt_part.
    DEFINE INPUT PARAMETER vvend LIKE vd_addr.
    DEFINE INPUT PARAMETER datet  AS DATE.
    DEFINE OUTPUT PARAMETER v1vd  AS LOGICAL.

/*     DEFINE VARIABLE datet AS DATE       NO-UNDO.  */
    DEFINE VARIABLE price AS DECIMAL    NO-UNDO.
    DEFINE VARIABLE minprice AS DECIMAL    NO-UNDO.
    DEFINE VARIABLE maxprice AS DECIMAL    NO-UNDO.
    DEFINE VARIABLE vprodline LIKE pt_prod_line NO-UNDO.
    DEFINE VARIABLE i AS INTEGER.
/*     ASSIGN datet  = TODAY - 5 .  */

    ASSIGN v1vd = YES.
    FOR FIRST pt_mstr NO-LOCK WHERE pt_part = vpart:
        ASSIGN vprodline = pt_prod_line.
    END.
    IF vprodline = "R190" THEN DO:
        ASSIGN v1vd = NO.
    END.
    ELSE do:
     FOR EACH CODE_mstr NO-LOCK WHERE CODE_fldname =  'PT2D9EID'
            AND CODE_value = STRING(YEAR(DATET),"9999") +
                             STRING(MONTH(DATET),'99'):
            ASSIGN i = integer(CODE_user1).
      END.

     FOR EACH CODE_mstr NO-LOCK WHERE  CODE_fldname= 'PT2D9EID'
          AND CODE_user1 <= STRING(I) AND CODE_user1 >= STRING( I - 3 )
            BREAK BY CODE_VALUE DESC:
              IF v1vd = NO THEN NEXT.
              IF CODE_CMMT = "PT9E" THEN DO:
                  IF NOT CAN-FIND (FIRST pt9e_det NO-LOCK WHERE
                                         pt9e_id = INTEGER(CODE_desc) AND
                                         pt9e_part=vpart AND
                                         pt9e_vend=vvend) THEN DO:
                      ASSIGN v1vd = NO.
                      NEXT.
                  END.
                  ELSE DO:
                       FOR EACH pt9e_det NO-LOCK WHERE
                                pt9e_id   = INTEGER(CODE_desc)
                            AND pt9e_part = vpart
                            AND pt9e_price > 0 AND pt9e_vend <> ''
                      BREAK BY pt9e_group BY pt9e_part BY pt9e_price:
                          IF FIRST-OF (pt9e_group)  THEN DO:
                              ASSIGN minprice = pt9e_price
                                     maxprice = 0
                                     price=0.
                          END.
                          IF FIRST-OF(pt9e_part) THEN DO:
                              IF LAST-OF (pt9e_part) THEN DO:
                                  ASSIGN v1vd = NO.
                              END.
                              IF pt9e_sub_part<>vpart OR
                                 pt9e_vend<> vvend THEN DO:
                                  ASSIGN v1vd = NO.
                                END.
                              minprice = pt9e_price.
                          END.
                          ELSE DO:
                             IF (pt9E_price - minprice) < 0.045 *  minprice
                             THEN  DO:
                                 ASSIGN v1vd = NO.
                             END.
                          END.
                      END.
                  END.
             END.  /*   IF CODE_CMMT = "PT9E" THEN DO: */
            ELSE DO:
                IF NOT CAN-FIND (FIRST pt2d_det NO-LOCK
                                 WHERE pt2d_id = INTEGER(CODE_desc)
                                   AND pt2d_part = vpart
                                   AND pt2d_vend = vvend) THEN DO:
                    ASSIGN v1vd = NO.
                    NEXT.
                END.
                ELSE DO:
                    FOR EACH pt2d_det NO-LOCK
                       WHERE pt2d_id=INTEGER(CODE_desc)
                         AND pt2d_part = vpart
                    BREAK BY pt2d_part BY pt2d_net_prc:
                        IF FIRST-OF (pt2d_part) THEN DO:
                            IF LAST-OF(pt2d_part) THEN DO:
                                ASSIGN v1vd = NO.
                                NEXT.
                            END.
                            IF pt2d_sub_part <> vpart OR
                               pt2d_vend <> vvend THEN DO:
                                ASSIGN v1vd = NO.
                                NEXT.
                            END.
                            ASSIGN minprice = pt2d_net_prc.
                        END.
                        ELSE DO:
                            IF(pt2d_net_prc - minprice) < 0.045 * minprice
                            THEN DO:
                                ASSIGN v1vd = NO.
                                NEXT.
                            END.
                        END.
                    END.
                END.
            END.
        END.
    END. /*** else IF vprodline = "R190" THEN DO:***********/
END PROCEDURE.

/* DEFINE VARIABLE OFFS AS LOGICAL  NO-UNDO.                                */
/*  RUN get1vdflag3 (INPUT '111-2361151R' , INPUT 'S1301',INPUT 10/30/2009, */
/*                   OUTPUT OFFS ).                                         */
/* MESSAGE OFFS   VIEW-AS ALERT-BOX INFO BUTTONS OK.                        */
